package com.ly.hotel.broadcast;


import java.lang.ref.WeakReference;

import com.ly.hotel.common.MyApplication;
import com.ly.hotel.msgevent.SetVodPlayEvent;

import de.greenrobot.event.EventBus;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

/**
 * @Description: 处理第三方apk发出的广播，通过广播来请求服务器
 * @author HanleyTowne
 * @email  tanghly@gmail.com
 * @date   2012-7-27下午6:05:50
 * @Google+ http://gplus.to/hanleytowne 
 */
public class HttpAgentReceiver extends BroadcastReceiver {
	private MyApplication app = (MyApplication) MyApplication.getContext();
	public final static String VIDEO_PLAY = "video-play";
	public final static String VIDEO_STOP = "video-stop";
	public String connent = "";
	public int filmId = -1;
	
	public ThisHandler handlerMsg = new ThisHandler(this);
	@Override
	public void onReceive(Context context, Intent intent) {
		connent = intent.getStringExtra("connent");
		filmId = intent.getIntExtra("filmId",-1);
		Log.i("HttpAgentReceiver", "收到http代理请求->" + connent + ",filmId=" + filmId);
		
		if(connent.equals(VIDEO_PLAY)){
			if(filmId != -1){
				EventBus.getDefault().post(new SetVodPlayEvent(filmId, SetVodPlayEvent.START));
				filmId = -1;
			}
		} else if(connent.equals(VIDEO_STOP)){
				EventBus.getDefault().post(new SetVodPlayEvent(filmId, SetVodPlayEvent.END));
		}
	}
	
	public static class ThisHandler extends Handler {
		private WeakReference<HttpAgentReceiver> wrActivity;

		public ThisHandler(HttpAgentReceiver virtualKeyReceiver) {
			wrActivity = new WeakReference<HttpAgentReceiver>(virtualKeyReceiver);
		}

		@Override
		public void handleMessage(Message message) {
			HttpAgentReceiver act = wrActivity.get();
			if (act != null) {
				switch (message.what) {
					case 0:

					}
			}
		}
	}
}
